package br.ufrj.ri.lbd.model;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import net.jbouchard.bool.BooleanExpression;

public class QueryModel
{	// Atributos: nome, query de busca dos termos e lista de documentos que satisfazem a query
	private String name, query;
	private ArrayList<String> documents = new ArrayList<String>();

	public QueryModel()
	{
		super();
	}

	public final String getName()
	{
		return this.name;
	}

	public final void setName(String name)
	{
		this.name = name;
	}

	public final String getQuery()
	{
		return this.query;
	}

	public final void setQuery(String query)
	{
		this.query = query;
	}

	public final List<String> getDocuments()
	{
		return this.documents;
	}

	public final void verify(List<IIModel> indexFiles)
	{	// Para cada documento (linha) na matriz
		for (IIModel model : indexFiles)
		{
			final Map<String, Boolean> map = model.getBoolIndex();
			final BooleanExpression expression = new BooleanExpression(this.query, map);

	        try
	        {
	            if (expression.evaluate(map))
	            {
	            	this.documents.add(model.getName());
	            }
	        }
	        catch (ParseException pe)
	        {
	            pe.printStackTrace();
	        }
		}
	}
}
